home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8434 / 8434.xpi / chrome / content / alert.js next >
Text File  |  2008-11-27  |  8KB  |  186 lines

  1. ∩╗┐/* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 1998
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Scott MacGregor <mscott@netscape.com>
  23.  *   Jens Bannmann <jens.b@web.de>
  24.  *   Pete Burgers <updatescanner@gmail.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39. if (typeof(USc_alert_exists) != 'boolean') {
  40. var USc_alert_exists = true;
  41. var USc_alert = {    
  42. _animateAlert:function () {
  43.     var prefService = Components.classes['@mozilla.org/preferences-service;1'].getService();
  44.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  45.     var prefBranch = prefService.getBranch("extensions.googleredesigned.notifications.");
  46.     var me = USc_alert;
  47.     if (window.outerHeight < me.gFinalHeight) {
  48.         window.screenY -= me.gSlideIncrement;
  49.         window.outerHeight += me.gSlideIncrement;
  50.         setTimeout(me._animateAlert, me.gSlideTime);
  51.     } else {
  52.         if (prefBranch.getBoolPref("playSound")) {
  53.             me._playSound();
  54.         }
  55.         if (!me.gPermanent) {
  56.             setTimeout(me._closeAlert, me.gOpenTime);
  57.         }
  58.     }
  59. },
  60. _closeAlert:function () {
  61.     var me = USc_alert;
  62.     if (window.outerHeight > 1) {
  63.         window.screenY += me.gSlideIncrement;
  64.         window.outerHeight -= me.gSlideIncrement;
  65.         setTimeout(me._closeAlert, me.gSlideTime);
  66.     } else {
  67.         if (me.gAlertListener) {
  68.             me.gAlertListener.observe(null, "alertfinished", me.gAlertCookie);
  69.         }
  70.         window.close();
  71.     }
  72. },
  73. _playSound:function () {
  74.     var prefService = Components.classes['@mozilla.org/preferences-service;1'].getService();
  75.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  76.     var prefBranch = prefService.getBranch("extensions.googleredesigned.notifications.");
  77.     var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
  78.     var url;
  79.     var player = Components.classes['@mozilla.org/sound;1'].createInstance(Components.interfaces.nsISound);
  80.     try {
  81.         if (prefBranch.getBoolPref("defaultSound")) {
  82.             url = ioService.newURI("chrome://googleredesigned/content/defaultNotification.wav", null, null);
  83.         } else {
  84.             var file = prefBranch.getComplexValue("soundFile", Components.interfaces.nsILocalFile);
  85.             url = ioService.newFileURI(file);
  86.         }
  87.         player.init();
  88.         player.play(url);
  89.     } catch (ex) {
  90.     }
  91. },
  92. gAlertCookie:"",
  93. gAlertListener:null,
  94. gAlertTextClickable:false,
  95. gFinalHeight:50,
  96. gOpenTime:3000,
  97. gPermanent:false,
  98. gSlideIncrement:4,
  99. gSlideTime:20,
  100. g_MAX_HEIGHT:134,
  101. onAlertClick:function () {
  102.     var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
  103.     var win = wm.getMostRecentWindow("navigator:browser");
  104.     if (win.toggleSidebar) {
  105.         win.toggleSidebar("viewgoogleredesignedSidebar");
  106.     }
  107.     win.focus();
  108. },
  109. onAlertClose:function () {
  110.     var me = USc_alert;
  111.     me._closeAlert();
  112. },
  113. onAlertLoad:function () {
  114.     var me = USc_alert;
  115.     try {
  116.         var prefService = Components.classes['@mozilla.org/preferences-service;1'].getService();
  117.         prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  118.         var prefBranch = prefService.getBranch("extensions.googleredesigned.notifications.");
  119.         me.gOpenTime = prefBranch.getIntPref("displayTime") * 1000;
  120.         if (window.arguments[3]) {
  121.             me.gOpenTime *= 2;
  122.         }
  123.         me.gPermanent = prefBranch.getBoolPref("permanent");
  124.     } catch (ex) {
  125.     }
  126.     sizeToContent();
  127.     me.gFinalHeight = window.outerHeight;
  128.     if (me.gFinalHeight > me.g_MAX_HEIGHT) {
  129.         me.gFinalHeight = me.g_MAX_HEIGHT;
  130.     }
  131.     window.outerHeight = 1;
  132.     window.moveTo((screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availTop + screen.availHeight - window.outerHeight);
  133.     setTimeout(me._animateAlert, me.gSlideTime);
  134. },
  135. prefillAlertInfo:function () {
  136.     var stringbundle = document.getElementById("googleredesigned-alert-strings");
  137.     var label = document.getElementById("message");
  138.     var labelvalue = "";
  139.     if (window.arguments[0] == "Updates saved succesfully for: ") {
  140.         labelvalue = stringbundle.getString("updatesSavedSuccessfullyFor");
  141.     }
  142.     if (window.arguments[0] == "Update saved succesfully for: ") {
  143.         labelvalue = stringbundle.getString("updateSavedSuccessfullyFor");
  144.     }
  145.     if (window.arguments[0] == "Could not connect to update server.") {
  146.         labelvalue = stringbundle.getString("couldntConnectToServer");
  147.     }
  148.     if (window.arguments[0] == "All styles are up-to-date") {
  149.         labelvalue = stringbundle.getString("allStylesAreUptodate");
  150.     }
  151.     label.value = labelvalue;
  152.     if (window.arguments[1]) {
  153.         var label1 = document.createElement("label");
  154.         var label1value = "";
  155.         if (window.arguments[1] == "Try again later.") {
  156.             label1value = stringbundle.getString("tryAgainLater");
  157.         } else {
  158.             label1value = window.arguments[1];
  159.         }
  160.         label1.setAttribute("value", label1value);
  161.         label1.setAttribute("style", "margin-bottom:5px");
  162.         document.getElementById("message").parentNode.appendChild(label1);
  163.     }
  164.     if (window.arguments[2]) {
  165.         var label2 = document.createElement("label");
  166.         var label2value = "";
  167.         if (window.arguments[2] == "Update unavailable for:") {
  168.             label2value = stringbundle.getString("updateAbortedFor");
  169.         }
  170.         if (window.arguments[2] == "Updates unavailable for:") {
  171.             label2value = stringbundle.getString("updatesAbortedFor");
  172.         }
  173.         label2.setAttribute("value", label2value);
  174.         document.getElementById("message").parentNode.appendChild(label2);
  175.     }
  176.     if (window.arguments[3]) {
  177.         label3 = document.createElement("label");
  178.         label3value = window.arguments[3];
  179.         label3.setAttribute("value", label3value);
  180.         label3.setAttribute("style", "margin-bottom:5px");
  181.         document.getElementById("message").parentNode.appendChild(label3);
  182.     }
  183. }
  184. }
  185. }
  186.